function showMonitoringPointSearch() {
	window.location.href = "showMonitoringPointSearch.do";
}

function ajaxFindMonitoringPointSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxMonitoringPointSearchList.do",
		data : {
			monitornum: $("#scMonitorNum").val(),
			monitorname: $("#scMonitorName").val(),
			sectionid: $("#scRoadSection").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listMonitoringPointBox").html(msg);
		}
	});
}

function ajaxFindMonitoringLaneList(){
	$.ajax({
		type : "post",
		url : "ajaxFindMonitoringLaneList.do",
		data : {
			//monitorNum:$("#monitorNum").val(),
			monitoringPointId:$("#id").val(),
			//按钮是否可见
			isVisible:$("#isVisible").val(),
		},
		success : function(msg) {
			$("#listMonitoringLaneBox").html(msg);
		}
	});
}

function ajaxShowMonitoringPointEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowMonitoringPointEdit.do",
		data:{monitoringPointId:id},
		success:function(msg){
			$("#dialog1").html(msg);
			$("#dialog1").dialog({
				autoOpen: true,
				width: 1000,
				title:$(".dialogtitle2").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveMonitoringPoint(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxShowMonitoringPointView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowMonitoringPointView.do",
		data:{monitoringPointId:id},
		success:function(msg){
			$("#dialog1").html(msg);
			$("#dialog1").dialog({
				autoOpen: true,
				width: 1000,
				title:$(".dialogtitle2").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxSaveMonitoringPoint(objDialog) {
	monitoringPointValidate();
	if ($("#frmMonitoringPoint").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveMonitoringPoint.do",
				success: function (msg) {
					clearInput("#sltMonitoringPoint");
					showMessageDialog("保存监控点","监控点信息保存成功。",null,dialogType.info);
					ajaxFindMonitoringPointSearchList();
				}
		};
		$("#frmMonitoringPoint").ajaxSubmit(options);
	}
}

function ajaxDeleteMonitoringPointById(id) {
	var monitoringPointIds="";
	var sltMP = $("#listMonitoringPointList tbody input:checked").length;
	if(id==null){
		$("#listMonitoringPointList tbody input:checked").each(function(){ 
			monitoringPointIds += $(this).val()+";";
		});
		if(sltMP == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			monitoringPointIds = monitoringPointIds.substring(0, monitoringPointIds.length-1);
		} 
	}else{
		monitoringPointIds=id;
		sltMP = 1;
	}
	if( monitoringPointIds!=null){
		showMessageDialog("提示","确定要删除所选"+sltMP+"条监控点信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteMonitoringPointByIds.do",
				data:{monitoringPointIds:monitoringPointIds},
				success:function(msg){
					ajaxFindMonitoringPointSearchList();
					showMessageDialog("提示","监控点信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}


function monitoringPointValidate(){
	$("#frmMonitoringPoint").validate({
		errorLabelContainer: $("#infoMonitoringPoint"),
		rules : {
			monitorname : {
				required :true				
			},
			monitornum : {
				required :true				
			},
			sectionid : {
				required :true				
			},
			longitude : {
				required :true				
			},
			latidue : {
				required :true				
			}
		},
		messages : {
			monitorname : {
				required :"请输入名称！"
			},
			monitornum : {
				required :"请输入编号！"
			},
			sectionid : {
				required :"请输入所在路况！"
			},
			longitude : {
				required :"请输入经度！"
			},
			latidue : {
				required :"请输入纬度！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}

function ajaxShowMonitoringLaneEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowMonitoringLaneEdit.do",
		data:{monitoringLaneId:id,monitoringPointId:$("#id").val()},
		success:function(msg){
			$("#dialog2").html(msg);
			$("#dialog2").dialog({
				autoOpen: true,
				width: 1000,
				title:$(".lanedialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveMonitoringLane(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxSaveMonitoringLane(objDialog) {
	monitoringLaneValidate();
	if ($("#frmMonitoringLane").valid()) {
		$("#monitoringLaneConfigList tbody input[type='hidden']").each(function (i) {$(this).attr("name","laneConfigList["+ i++ +"].id");});
		$("#monitoringVehicleTravelStrategyList tbody input[type='hidden']").each(function (i) {$(this).attr("name","drivingstrategyList["+ i++ +"].id");});
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveMonitoringLane.do",
				success: function (msg) {
					showMessageDialog("保存监控车道","监控车道信息保存成功。",null,dialogType.info);
					ajaxFindMonitoringLaneList();
				}
		};
		$("#frmMonitoringLane").ajaxSubmit(options);
	}
}

function ajaxShowMonitoringLaneView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowMonitoringLaneView.do",
		data:{monitoringLaneId:id},
		success:function(msg){
			$("#dialog2").html(msg);
			$("#dialog2").dialog({
				autoOpen: true,
				width: 1000,
				title:$(".lanedialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxDeleteMonitoringLaneById(id) {
	if( id!=null){
		showMessageDialog("提示","确定要删除该监控车道吗？",
		  function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteMonitoringLaneById.do",
				data:{monitoringLaneId:id},
				success:function(msg){
					ajaxFindMonitoringLaneList();
					showMessageDialog("提示","监控车道信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function monitoringLaneValidate(){
	$("#frmMonitoringLane").validate({
		errorLabelContainer: $("#infoMonitoringLane"),
		rules : {
			lanenum : {
				required :true				
			}
		},
		messages : {
			lanenum : {
				required :"请输入车道号！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}